﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace testgame
{
    /// <summary>
    /// 游戏类
    /// </summary>
    class Game
    {
        private const int GameWidth = 600;//假定游戏区域
        private const int GameHeight = 400;
        Image avatar = Properties.Resources.playerpanda;     //角色头像图片
        private LaunchCanister launchCanister;//初始化发射筒

        public Game()
        {
            launchCanister = new LaunchCanister(GameWidth);//给发射筒赋值
        }
        
        /// <summary>
        /// 绘制游戏界面
        /// </summary>
        /// <param name="g"></param>
        public void DrawGame(Graphics g, Size size)                    //绘制界面上所有图像
        {

            //定义一张空白的图
            Image img = new Bitmap(GameWidth, GameHeight);

            //空白图上的绘图句柄
            Graphics _g = Graphics.FromImage(img);
            //空白图上的矩形
            Rectangle rec = new Rectangle(new Point(0, 0), new Size(GameWidth, GameHeight));


            _g.DrawImage(Properties.Resources.bg, rec);//绘制背景

            _g.DrawImage(avatar, 10, 10,100,100);                                            //绘制角色头像
            _g.DrawRectangle(new Pen(Color.Black), new Rectangle(10, 100, 100, 10));     //绘制血条矩形
            _g.FillRectangle(Brushes.Red, 10, 101, LaunchCanister.health, 9);                   //填充血条矩形

            _g.DrawRectangle(new Pen(Color.Blue), new Rectangle(10, 120, 100, 10)); //绘制分数矩形
            _g.FillRectangle(Brushes.Green, 11, 121, LaunchCanister.score, 9);  //填充分数矩形

            _g.DrawString("Player：zl", new Font("宋体", 9, FontStyle.Bold), Brushes.Yellow, new Point(10, 140));      //显示玩家
            _g.DrawString("Health：" + LaunchCanister.health , new Font("宋体", 9, FontStyle.Bold), Brushes.Yellow, new Point(10, 160));      //显示分数
            _g.DrawString("Score：" + LaunchCanister.score, new Font("宋体", 9, FontStyle.Bold), Brushes.Yellow, new Point(10, 180));      //显示分数

            //绘制飞机及飞机的移动
            LaunchCanister.LCShow(_g);
            LaunchCanister.LCMove();

            //绘制我方子弹及子弹的移动及子弹与怪兽碰撞
            Bullet.ProduceMybul();
            Bullet.MoveMybul(_g);
            Bullet.IsHitEnemy(_g);

            //绘制怪兽及怪兽的移动
            monster.ProduceMonster();
            monster.monsterMove(_g);

            //绘制敌方子弹及子弹的移动及子弹与飞机碰撞
            monsterBullet.ProduceMonbul();
            monsterBullet.Movemonbul(_g);
            monsterBullet.HitLC(_g);

            if(LaunchCanister.health <=0)
            {
                _g.DrawImage(Properties.Resources.gameover, 200, 100, 200, 200);
              
            }
            if (LaunchCanister.score>=100&&LaunchCanister.health!=0)
            {
                _g.DrawImage(Properties.Resources.win2 , 200, 100, 200, 200);
            }

            //todo
            g.DrawImage(img, new Rectangle(new Point(0, 0), size));
            
        }
    }
}
